package nbcp

import org.slf4j.LoggerFactory
import org.springframework.boot.autoconfigure.SpringBootApplication

import nbcp.base.utils.SpringUtil
import nbcp.web.HttpContext
import org.springframework.boot.runApplication
import org.springframework.boot.web.servlet.ServletComponentScan
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Import
import nbcp.base.extend.AsLocalDateTime
import nbcp.base.extend.AsString
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo
import org.apache.dubbo.container.Main
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
import org.springframework.context.annotation.PropertySource
import org.springframework.scheduling.annotation.EnableScheduling
import org.springframework.web.client.RestTemplate
import java.time.Instant
import java.time.ZoneId
import java.util.*

//import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession

val xmz_corp_id = "5ced4009892a1b2d206d5cf6"


@EnableDubbo(scanBasePackages = arrayOf("nbcp.client"))
@SpringBootApplication(exclude = arrayOf(DataSourceAutoConfiguration::class))
//@EnableDiscoveryClient
@Import(SpringUtil::class)
@ServletComponentScan
//@EnableRedisHttpSession
class MainApplication {
    companion object {
        val logger = LoggerFactory.getLogger(this::class.java.declaringClass)
    }

//    @Bean
//    @LoadBalanced
//    fun getTemplate(): RestTemplate {
//        return RestTemplate();
//    }
}


fun main(args: Array<String>) {
//    局显示定义最省事安全
//    Locale.setDefault(Locale.ENGLISH);//推荐用英语地区的算法
    System.setProperty("user.timezone", "Asia/Shanghai");
    TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));

    var context = runApplication<MainApplication>(*args)

    MainApplication.logger.warn("""
        ================================================
              ${(context as ServletWebServerApplicationContext).servletContext!!.serverInfo} ${context.environment.getProperty("spring.application.name")} (${context.environment.activeProfiles.joinToString(",")} : ${context.environment.getProperty("server.port")})
        ================================================
""")

//    Main.main(args);


//
//    SystemContext.getUserNameFunc = {
//
//        var request = HttpContext.nullableRequest;
//        if (request == null) "";
//        else request!!.UserName;
//    }
}
//private var mqThread: Thread? = null